package cn.zzuli.manager.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.zzuli.manager.entity.NewsEntity;
import cn.zzuli.manager.service.NewsService;
import cn.zzuli.common.utils.PageUtils;
import cn.zzuli.common.utils.R;


/**
 * 新闻详情表
 *
 * @author Huanghuan
 * @email 17719158821@163.com
 * @date 2020-11-20 00:42:30
 */
@RestController
@RequestMapping("manager/news")
public class NewsController {
    @Autowired
    private NewsService newsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = newsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{newsId}")
    public R info(@PathVariable("newsId") Integer newsId) {
        NewsEntity news = newsService.getById(newsId);

        return R.ok().put("news", news);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody NewsEntity news) {
        newsService.save(news);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody NewsEntity news) {
        newsService.updateById(news);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] newsIds) {
        newsService.removeByIds(Arrays.asList(newsIds));

        return R.ok();
    }

}
